Skip to content

Read number plates locally with Ultralytics OCR instead of OpenAI - #121

Merged
glenn-jocher merged 3 commits into
mainfrom
anpr-yolo-ocr
Nov 19, 2026
Merged

glenn-jocher merged 3 commits into
mainfrom
anpr-yolo-ocr

Conversation

@glenn-jocher

@glenn-jocher glenn-jocher commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

The ANPR notebook now reads plates with the Ultralytics OCR solution (solutions.OCR, PP-OCRv6 on ONNX Runtime) instead of sending every plate crop in every frame to OpenAI gpt-4o-mini. It runs offline, needs no API key, and costs nothing per frame.

Changes

  • Rewrite the notebook around solutions.OCR(model="anpr-demo-model.pt", imgsz=640). The demo plate detector feeds the same detection-then-recognition path as YOLO26-Text, and the solution draws each plate's text on the frame. This replaces the OpenAI client, the prompt, the base64 encoding and the manual crop/annotate loop.
  • Rename the notebook from how-to-use-ultralytics-yolo-with-openai-for-number-plate-recognition.ipynb to how-to-use-ultralytics-yolo-ocr-for-number-plate-recognition.ipynb. Only this repo linked to the old path (org-wide code search).
  • Update the docs/notebooks-data.yml entry and its README rows. The GPT-4o blog and YouTube links are dropped because they describe the old approach, and the documentation link now points to the OCR guide.
  • Replace the output image with a frame from this pipeline: anpr-yolo-ocr-output.jpg, uploaded to the v0.0.0 release next to the other notebook images.
  • Clear stale outputs from the cells that changed.

Validation

I ran the notebook's code cells as written (Python 3.12, ultralytics 8.4.215, Apple CPU, ONNX Runtime 1.32):

  • It processed all 168 frames of anpr-demo-video.mp4 and wrote anpr-output.avi.
  • Plates read stably across frames, e.g. 8884KA-4 (0.97–1.00), 3066MP-4 (1.00), AP 4895-5 (0.95–0.99).
  • The demo detector is a proof of concept and also boxes some non-plate text, as the notebook already notes.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

The ANPR notebook now uses Ultralytics’ OCR solution to recognize detected plates locally and updates its name and documentation links accordingly.

📊 Key Changes

  • Replaced OpenAI gpt-4o-mini, its API client, and manual crop/encoding/annotation code with solutions.OCR(model="anpr-demo-model.pt", imgsz=640) and the PP-OCRv6 recognizer.
  • Updated frame processing to print recognized plate text and save frames annotated by the OCR solution to anpr-output.avi.
  • Renamed the notebook and updated its catalog entries in both READMEs and docs/notebooks-data.yml; the documentation link now points to the OCR guide.
  • Replaced the displayed output image and cleared outputs from edited cells.

🎯 Purpose & Impact

  • The example no longer sends plate crops to OpenAI or requires an OpenAI API key; plate detection and recognition run through the local OCR workflow, with the recognizer downloaded on first use.

@UltralyticsAssistant UltralyticsAssistant added documentation Improvements or additions to documentation enhancement New feature or request solutions Ultralytics Solutions issues, PR's, Discussions labels Nov 19, 2026
@UltralyticsAssistant

Copy link
Copy Markdown
Member

👋 Hello @glenn-jocher, thank you for submitting a ultralytics/notebooks 🚀 PR! This automated message confirms your contribution was received, and an Ultralytics engineer will assist with the review. To ensure a seamless integration of your work, please review the following checklist:

  • ✅ Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • ✅ Synchronize with Source: Confirm your PR is synchronized with the ultralytics/notebooks main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • ✅ Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • ✅ Update Documentation: Update the relevant documentation for any new or modified features.
  • ✅ Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • ✅ Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR; the CLA check will comment with signing instructions if needed.
  • ✅ Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Reviewed the OCR notebook rewrite, catalog metadata, and README entries. The processing flow and OCR result handling are consistent; no concrete regressions found. LGTM.

@glenn-jocher
glenn-jocher merged commit 003ceea into main Nov 19, 2026
7 checks passed
@glenn-jocher
glenn-jocher deleted the anpr-yolo-ocr branch November 19, 2026 01:25
@UltralyticsAssistant

Copy link
Copy Markdown
Member

🎉 This PR is merged—thank you, @glenn-jocher! The notebook now demonstrates local plate recognition with Ultralytics’ OCR solution instead of sending plate crops to OpenAI.

“The best way to predict the future is to invent it.” — Alan Kay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request solutions Ultralytics Solutions issues, PR's, Discussions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants